﻿/*
  In App.xaml:
  <Application.Resources>
      <vm:GlobalViewModelLocator xmlns:vm="clr-namespace:MyMeetup.ViewModels"
                                   x:Key="Locator" />
  </Application.Resources>
  
  In the View:
  DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
*/

using MyMeetup.ViewModel;

namespace MyMeetup.ViewModels
{
    /// <summary>
    /// This class contains static references to all the view models in the
    /// application and provides an entry point for the bindings.
    /// <para>
    /// Use the <strong>mvvmlocatorproperty</strong> snippet to add ViewModels
    /// to this locator.
    /// </para>
    /// <para>
    /// In Silverlight and WPF, place the GlobalViewModelLocator in the App.xaml resources:
    /// </para>
    /// <code>
    /// &lt;Application.Resources&gt;
    ///     &lt;vm:GlobalViewModelLocator xmlns:vm="clr-namespace:MyMeetup.ViewModels"
    ///                                  x:Key="Locator" /&gt;
    /// &lt;/Application.Resources&gt;
    /// </code>
    /// <para>
    /// Then use:
    /// </para>
    /// <code>
    /// DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
    /// </code>
    /// <para>
    /// You can also use Blend to do all this with the tool's support.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class GlobalViewModelLocator
    {
        /// <summary>
        /// Initializes a new instance of the GlobalViewModelLocator class.
        /// </summary>
        public GlobalViewModelLocator()
        {
            ////if (ViewModelBase.IsInDesignModeStatic)
            ////{
            ////    // Create design time view models
            ////}
            ////else
            ////{
            ////    // Create run time view models
            ////}
        
            CreateMainPageViewModel();
            CreateMySettingsViewModel();
            CreateMemberPageViewModel();
            CreateEventPageViewModel();
            CreateGroupPageViewModel();
            CreateSearchPageViewModel();
            CreateAlbumPageViewModel();
        }

        public static void Cleanup()
        {
            // TODO Clear the ViewModels
            ClearMainPageViewModel();
            ClearMySettingsViewModel();
            ClearMemberPageViewModel();
            ClearEventPageViewModel();
            ClearGroupPageViewModel();
            ClearSearchPageViewModel();
            ClearAlbumPageViewModel();

        }

        private static MainPageViewModel _mainPageViewModel;

        /// <summary>
        /// Gets the MainPageViewModel property.
        /// </summary>
        public static MainPageViewModel MainPageViewModelStatic
        {
            get
            {
                if (_mainPageViewModel == null)
                {
                    CreateMainPageViewModel();
                }

                return _mainPageViewModel;
            }
        }

        /// <summary>
        /// Gets the MainPageViewModel property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MainPageViewModel MainPageViewModel
        {
            get
            {
                return MainPageViewModelStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the MainPageViewModel property.
        /// </summary>
        public static void ClearMainPageViewModel()
        {
            _mainPageViewModel.Cleanup();
            _mainPageViewModel = null;
        }

        /// <summary>
        /// Provides a deterministic way to create the MainPageViewModel property.
        /// </summary>
        public static void CreateMainPageViewModel()
        {
            if (_mainPageViewModel == null)
            {
                _mainPageViewModel = new MainPageViewModel();
            }
        }

        private static MySettingsViewModel _mySettingsViewModel;

        /// <summary>
        /// Gets the MySettingsViewModel property.
        /// </summary>
        public static MySettingsViewModel MySettingsViewModelStatic
        {
            get
            {
                if (_mySettingsViewModel == null)
                {
                    CreateMySettingsViewModel();
                }

                return _mySettingsViewModel;
            }
        }

        /// <summary>
        /// Gets the MySettingsViewModel property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MySettingsViewModel MySettingsViewModel
        {
            get
            {
                return MySettingsViewModelStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the MySettingsViewModel property.
        /// </summary>
        public static void ClearMySettingsViewModel()
        {
            _mySettingsViewModel.Cleanup();
            _mySettingsViewModel = null;
        }

        /// <summary>
        /// Provides a deterministic way to create the MySettingsViewModel property.
        /// </summary>
        public static void CreateMySettingsViewModel()
        {
            if (_mySettingsViewModel == null)
            {
                _mySettingsViewModel = new MySettingsViewModel();
            }
        }


        private static GroupPageViewModel _groupPageViewModel;

        /// <summary>
        /// Gets the GroupPageViewModel property.
        /// </summary>
        public static GroupPageViewModel GroupPageViewModelStatic
        {
            get
            {
                if (_groupPageViewModel == null)
                {
                    CreateGroupPageViewModel();
                }

                return _groupPageViewModel;
            }
        }

        /// <summary>
        /// Gets the GroupPageViewModel property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public GroupPageViewModel GroupPageViewModel
        {
            get
            {
                return GroupPageViewModelStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the GroupPageViewModel property.
        /// </summary>
        public static void ClearGroupPageViewModel()
        {
            _groupPageViewModel.Cleanup();
            _groupPageViewModel = null;
        }

        /// <summary>
        /// Provides a deterministic way to create the GroupPageViewModel property.
        /// </summary>
        public static void CreateGroupPageViewModel()
        {
            if (_groupPageViewModel == null)
            {
                _groupPageViewModel = new GroupPageViewModel();
            }
        }


        private static EventPageViewModel _eventPageViewModel;

        /// <summary>
        /// Gets the EventPageViewModel property.
        /// </summary>
        public static EventPageViewModel EventPageViewModelStatic
        {
            get
            {
                if (_eventPageViewModel == null)
                {
                    CreateEventPageViewModel();
                }

                return _eventPageViewModel;
            }
        }

        /// <summary>
        /// Gets the EventPageViewModel property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public EventPageViewModel EventPageViewModel
        {
            get
            {
                return EventPageViewModelStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the EventPageViewModel property.
        /// </summary>
        public static void ClearEventPageViewModel()
        {
            _eventPageViewModel.Cleanup();
            _eventPageViewModel = null;
        }

        /// <summary>
        /// Provides a deterministic way to create the EventPageViewModel property.
        /// </summary>
        public static void CreateEventPageViewModel()
        {
            if (_eventPageViewModel == null)
            {
                _eventPageViewModel = new EventPageViewModel();
            }
        }


        private static MemberPageViewModel _memberPageViewModel;

        /// <summary>
        /// Gets the MemberPageViewModel property.
        /// </summary>
        public static MemberPageViewModel MemberPageViewModelStatic
        {
            get
            {
                if (_memberPageViewModel == null)
                {
                    CreateMemberPageViewModel();
                }

                return _memberPageViewModel;
            }
        }

        /// <summary>
        /// Gets the MemberPageViewModel property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MemberPageViewModel MemberPageViewModel
        {
            get
            {
                return MemberPageViewModelStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the MemberPageViewModel property.
        /// </summary>
        public static void ClearMemberPageViewModel()
        {
            _memberPageViewModel.Cleanup();
            _memberPageViewModel = null;
        }

        /// <summary>
        /// Provides a deterministic way to create the MemberPageViewModel property.
        /// </summary>
        public static void CreateMemberPageViewModel()
        {
            if (_memberPageViewModel == null)
            {
                _memberPageViewModel = new MemberPageViewModel();
            }
        }


        private static SearchPageViewModel _searchPageViewModel;

        /// <summary>
        /// Gets the SearchPageViewModel property.
        /// </summary>
        public static SearchPageViewModel SearchPageViewModelStatic
        {
            get
            {
                if (_searchPageViewModel == null)
                {
                    CreateSearchPageViewModel();
                }

                return _searchPageViewModel;
            }
        }

        /// <summary>
        /// Gets the SearchPageViewModel property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public SearchPageViewModel SearchPageViewModel
        {
            get
            {
                return SearchPageViewModelStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the SearchPageViewModel property.
        /// </summary>
        public static void ClearSearchPageViewModel()
        {
            _searchPageViewModel.Cleanup();
            _searchPageViewModel = null;
        }

        /// <summary>
        /// Provides a deterministic way to create the SearchPageViewModel property.
        /// </summary>
        public static void CreateSearchPageViewModel()
        {
            if (_searchPageViewModel == null)
            {
                _searchPageViewModel = new SearchPageViewModel();
            }
        }

        private static AlbumPageViewModel _albumPageViewModel;

        /// <summary>
        /// Gets the AlbumPageViewModel property.
        /// </summary>
        public static AlbumPageViewModel AlbumPageViewModelStatic
        {
            get
            {
                if (_albumPageViewModel == null)
                {
                    CreateAlbumPageViewModel();
                }

                return _albumPageViewModel;
            }
        }

        /// <summary>
        /// Gets the AlbumPageViewModel property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public AlbumPageViewModel AlbumPageViewModel
        {
            get
            {
                return AlbumPageViewModelStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the AlbumPageViewModel property.
        /// </summary>
        public static void ClearAlbumPageViewModel()
        {
            _albumPageViewModel.Cleanup();
            _albumPageViewModel = null;
        }

        /// <summary>
        /// Provides a deterministic way to create the AlbumPageViewModel property.
        /// </summary>
        public static void CreateAlbumPageViewModel()
        {
            if (_albumPageViewModel == null)
            {
                _albumPageViewModel = new AlbumPageViewModel();
            }
        }


        private static PhotoPageViewModel _photoPageViewModel;

        /// <summary>
        /// Gets the PhotoPageViewModel property.
        /// </summary>
        public static PhotoPageViewModel PhotoPageViewModelStatic
        {
            get
            {
                if (_photoPageViewModel == null)
                {
                    CreatePhotoPageViewModel();
                }

                return _photoPageViewModel;
            }
        }

        /// <summary>
        /// Gets the PhotoPageViewModel property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public PhotoPageViewModel PhotoPageViewModel
        {
            get
            {
                return PhotoPageViewModelStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the PhotoPageViewModel property.
        /// </summary>
        public static void ClearPhotoPageViewModel()
        {
            _photoPageViewModel.Cleanup();
            _photoPageViewModel = null;
        }

        /// <summary>
        /// Provides a deterministic way to create the PhotoPageViewModel property.
        /// </summary>
        public static void CreatePhotoPageViewModel()
        {
            if (_photoPageViewModel == null)
            {
                _photoPageViewModel = new PhotoPageViewModel();
            }
        }


        private static MapViewModel _mapViewModel;

        /// <summary>
        /// Gets the MapViewModel property.
        /// </summary>
        public static MapViewModel MapViewModelStatic
        {
            get
            {
                if (_mapViewModel == null)
                {
                    CreateMapViewModel();
                }

                return _mapViewModel;
            }
        }

        /// <summary>
        /// Gets the MapViewModel property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MapViewModel MapViewModel
        {
            get
            {
                return MapViewModelStatic;
            }
        }


        private static RateItViewModel _rateItViewModel;

        /// <summary>
        /// Gets the RateItViewModel property.
        /// </summary>
        public static RateItViewModel RateItViewModelStatic
        {
            get
            {
                if (_rateItViewModel == null)
                {
                    CreateRateItViewModel();
                }

                return _rateItViewModel;
            }
        }

        /// <summary>
        /// Gets the RateItViewModel property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public RateItViewModel RateItViewModel
        {
            get
            {
                return RateItViewModelStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the RateItViewModel property.
        /// </summary>
        public static void ClearRateItViewModel()
        {
            _rateItViewModel.Cleanup();
            _rateItViewModel = null;
        }

        /// <summary>
        /// Provides a deterministic way to create the RateItViewModel property.
        /// </summary>
        public static void CreateRateItViewModel()
        {
            if (_rateItViewModel == null)
            {
                _rateItViewModel = new RateItViewModel();
            }
        }


        /// <summary>
        /// Provides a deterministic way to delete the MapViewModel property.
        /// </summary>
        public static void ClearMapViewModel()
        {
            _mapViewModel.Cleanup();
            _mapViewModel = null;
        }

        /// <summary>
        /// Provides a deterministic way to create the MapViewModel property.
        /// </summary>
        public static void CreateMapViewModel()
        {
            if (_mapViewModel == null)
            {
                _mapViewModel = new MapViewModel();
            }
        }



    }
}